package com.atguigu.service.impl;

import com.atguigu.bean.User;
import com.atguigu.dao.UserDao;
import com.atguigu.dao.impl.UserDaoImpl;
import com.atguigu.service.UserService;
import com.atguigu.util.MDSUtil;

public class UserServiceImpl implements UserService {
    @Override
    public User login(String username, String password) {
        //根据用户名找用户
        UserDao userDao = new UserDaoImpl();
        User user = userDao.findUserByUsername(username);
        if(user!=null){
            //密码部分进行加密（MD5加密算法进行加密）
            if(user.getPassword().equals(MDSUtil.encode(password))){
                return user;
            }
        }
        return null;
    }

    @Override
    public boolean regist(User user) {
        //注册 添加到数据库
        UserDao userDao = new UserDaoImpl();
        user.setPassword(MDSUtil.encode(user.getPassword()));
        return userDao.saveUser(user);
    }

    @Override
    public User findUserByUsername(String username) {
        UserDao userDao = new UserDaoImpl();
        return userDao.findUserByUsername(username);
    }
}
